<template>
     <div class="components-container">
         <div class="header-form">
            <div class="layui-inline">
                <label class="layui-form-label" >逝者姓名</label>
                <div class="layui-input-inline">
                    <el-input v-model="selectData.IcdregnameLike" ></el-input>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label" >接运地址</label>
                <div class="layui-input-inline">
                    <el-input v-model="selectData.IcdaddressLike" ></el-input>
                </div>
            </div>
            <div class="layui-inline">
                  <label class="layui-form-label" >接运日期</label>
                  <el-date-picker v-date v-model="selectData.IcddateGreaterAndEquals" type="date" placeholder="大于等于该日期" style="width: 200px">
                  </el-date-picker>
                  <el-date-picker v-date v-model="selectData.IcddateLessAndEquals" type="date" placeholder="小于等于该日期" style="width: 200px">
                  </el-date-picker>
            </div>
            <el-button type="primary" :disabled="downloadLoading" @click="btnSearch" :loading="this.$store.state.isloading" >搜索</el-button>
            <el-button :disabled="this.$store.state.isloading || downloadLoading"  @click="btnRepeat">重置</el-button>
        </div>
        <div style="margin-top:10px;">
          <ul class="toolList"> 
            <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
              <el-button type="primary" :disabled="$store.state.isloading" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
            </li>
            <li>
            <el-button type="primary" :disabled="this.$store.state.isloading"  @click="exportExcel">导出Excel</el-button>
            </li>
          </ul>
        </div>
        <dataTable :headList="headList" :dataList="dataList" :isIndex="true" :pageOrder="pageOrder" :hiddenPageOrder="false" :height="height" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
        <!-- <cemeteryData ref="simpleReg"  @refreshData="getData"></cemeteryData> -->
        <printmodal ref="printPdf"></printmodal>
        <cemeteryData ref="simpleReg" :orderType="order" @refreshData="getData"></cemeteryData>
     </div>
</template>

<script>
import dataTable from "@/components/Table/DataTable";
import cemeteryData from "./hullDataDetail";

import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
import printmodal from "@/components/Pdf/Print";
import { PRINT } from "@/components/Pdf/PDF.js";
// import cresimplereg from "../businessHall/cresimplereg";
const INFO = "详情";
const EXPORT = "导出";
const MODIFY = "修改";
const ADD = "新增";
const DELETE = "删除";
export default {
  name: "iceuseSearch",
  mixins: [manage],
  data() {
    return {
      all: null,
      selectData: {
        IcdtypeEquals: '2',
        IcdregnameLike: null,
        IcdaddressLike: null,
        IcddateGreaterAndEquals: null,
        IcddateLessAndEquals: null,
      },
      usetype: [],
      activeName: "results",
      height: "620",
      downloadLoading: false,
    };
  },
  methods: {
    exportExcel() {
      var startTime;
      var endTime;
      if (this.selectData.IcddateGreaterAndEquals) {
        startTime = this.selectData.IcddateGreaterAndEquals.toLocaleDateString();
      } else {
        startTime = "空";
      }
      if (this.selectData.IcddateLessAndEquals) {
        endTime = this.selectData.IcddateLessAndEquals.toLocaleDateString();
      } else {
        endTime = "空";
      }
      let useState;
      if (this.selectData.IcdaddressLike == null) {
        useState =
          "守灵室使用" +
          "_" +
          "全部" +
          "(" +
          startTime +
          "--" +
          endTime +
          ")";
      } else {
        useState =
          "守灵室使用" +
          "_" +
          this.selectData.IcdaddressLike +
          "(" +
          startTime +
          "--" +
          endTime +
          ")";
      }
      if (this.dataList.length === 0) {
        this.$message.error("无导出数据！");
        return;
      }
      this.downloadLoading = true;
      require.ensure([], () => {
        const { export_json_to_excel } = require("@/vendor/Export2Excel");
        export_json_to_excel(this.headList, this.dataList, useState);
        this.downloadLoading = false;
      });
    },
    //功能操作
    operate(order) {
      this.order = order;
      console.log(this.order);
      switch (this.order) {
        case INFO:
          this.$refs.simpleReg.open(this.order, this.currentRow.ICDID);
          break;
        // case EXPORT:
        //   this.$refs.printPdf.report(
        //     PRINT.PDFICEDISPATCHSEARCH,
        //     this.getDataC()
        //   );
        //   break;
        case DELETE:
          this.$refs.simpleReg.open("删除", this.currentRow.ICDID);
          break;
        case MODIFY:
          this.$refs.simpleReg.open("修改", this.currentRow.ICDID);
          break;
        case ADD:
          this.$refs.simpleReg.open("新增");
        default:
      }
    },
    getColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetMourningUseColumns,
        res => {
          this.headList = res.data.content;
        }
      );
    },
    getDataC() {
      let Data = JSON.parse(JSON.stringify(this.selectData));
      if (!this.selectData.RegbusnumEquals) {
        Data.RegbusnumEquals = null;
      }
      Data.IchbegdateGreaterAndEquals = formatDate(
        Data.IchbegdateGreaterAndEquals,
        "yyyyMMdd"
      );
      Data.IchbegdateLessAndEquals = formatDate(
        Data.IchbegdateLessAndEquals,
        "yyyyMMdd"
      );
      let data = {
        PageIndex: -1,
        PageSize: 0,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: Data
      };
      return data;
    },
    getData() {
      let Data = JSON.parse(JSON.stringify(this.selectData));
      if (!this.selectData.IcdaddressLike) {
        Data.IcdaddressLike = null;
      }
      Data.IcddateGreaterAndEquals = formatDate(
        Data.IcddateGreaterAndEquals,
        "yyyyMMdd"
      );
      Data.IcddateLessAndEquals = formatDate(
        Data.IcddateLessAndEquals,
        "yyyyMMdd"
      );
      let data = {
        Data: Data
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Refrigerateddata.Query,
        res => {
          this.dataList = res.data.content.OutData;
          this.activeName = "results";
          this.pageOrder.totalNum = res.data.content.RecordCount;
        }
      );
    },
    //获取业务状态
    getIchStatus() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().IceUse.GetIchStatus,
        res => {
          this.usetype = res.data.content;
        }
      );
    },
    btnShow(btn) {
      switch (btn) {
        // case "导出":
        //   return true;
        //   break;
        case "新增":
          return true;
          break;
        case "修改":
          return true;
          break;
        case "删除":
          return true;
          break;
        case "详情":
          return true;
          break;
        default:
          return false;
      }
    },
    //查询条件重置
    btnRepeat() {
      this.selectData = {
        IcdtypeEquals: '2',
        IchstatusEqual: null,
        RegbusnumEquals: null,
        IchbegdateGreaterAndEquals: null,
        IchbegdateLessAndEquals: null
      };
      this.selectData.IchbegdateGreaterAndEquals = new Date(946662995000);
      // this.selectData.IchbegdateGreaterAndEquals.setDate(1);
      this.selectData.IchbegdateLessAndEquals = new Date();
      var day = new Date();
      var year = day.getFullYear();
      var month = day.getMonth() + 1;
      var d = new Date(year, month, 0);
      var dat = d.getDate();
      // this.selectData.IchbegdateLessAndEquals.setDate(dat);
      this.getData();
    }
  },
  mounted() {
    // console.log(this.all);
    this.selectData.IchstatusEqual = "A";
  },
  components: {
    dataTable,
    cemeteryData,
    // cresimplereg,
    printmodal
  },
  created() {
    this.selectData.IchbegdateGreaterAndEquals = new Date(946662995000);
    // this.selectData.IchbegdateGreaterAndEquals.setDate(1);
    this.selectData.IchbegdateLessAndEquals = new Date();
    this.selectData.IchstatusEqual = "A";
    var day = new Date();
    var year = day.getFullYear();
    var month = day.getMonth() + 1;
    var d = new Date(year, month, 0);
    var dat = d.getDate();
    // this.selectData.IchbegdateLessAndEquals.setDate(dat);
    this.getColumns(); //获取headerlist
    this.getData(); //获取数据
    this.getIchStatus(); //获取业务状态
  }
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
</style>

